import { defineStore } from "pinia";
import { type common_login_type, type User } from "@/types/CommonUser"
import { common_login, common_list, common_update, common_delete } from "@/apis/CommonUserApi"
import { ElMessage } from "element-plus";

const CommonStore = defineStore('CommonStore', () => {

    const register = async (data: common_login_type) => {
        await common_login(data)
    }
    const get_user_list = async (currentPage: number) => {
        const result = await common_list(currentPage)


        return result
    }
    const common_user_update = async (data: User) => {
        const result: any = await common_update(data)
        if (result.code === 200) {
            ElMessage({
                type: "success",
                message: "修改成功"
            })
        }
    }
    const common_user_delete = async (_id: string) => {
        await common_delete(_id)
    }
    return {
        register,
        get_user_list,
        common_user_update,
        common_user_delete
    }
})


export default CommonStore